package com.googlecode.mailnet.math;

import com.googlecode.mailnet.math.distribution.Distribution;

import java.util.Random;

/**
 * Holds global {@link java.util.Random} instance.
 *
 * @author Iskander Akishev
 */
public class RandomUtil {

	private final static Random random = new Random();

    public static double nextDouble() {
        return random.nextDouble();
    }

    public static boolean nextBoolean(double probability) {
        return nextDouble() < probability;
    }

    public static int nextInteger(Distribution distribution) {
        return Math.max(1, (int) Math.round(distribution.getValue()));
    }

    public static double nextGaussian() {
        return random.nextGaussian();
    }

	private RandomUtil() { }
}
